import { Ajax } from '../utils/http';

export class ResearchDetailService {
    private id: string;
    constructor(_id: string,) {
        this.id = _id;
    }

    public async send(): Promise<ResearchDetailData> {
        let response: ResearchDetailData;
        let data = {
            id: this.id,
        }
        try {
            response = await new Ajax<ResearchDetailData>('/article/articleInfo', data).post();
        } catch (e) {
            throw e;
        }
        return response;
    }
}

export class ResearchLikeService {
    private id?: string;
    private status?: number;
    constructor(_id?: string, _status?: number) {
        this.id = _id;
        this.status = _status;
    }

    public async send() {
        let data = {
            objectid: this.id,
            status: this.status,
            objecttype: 1
        }
        try {
            await new Ajax('/article/articleLike', data).post();
        } catch (e) {
            throw e;
        }
    }
}

export class ResearchFollowService {

    private id?: string;
    private status?: number;
    constructor(_id?: string, _status?: number) {
        this.id = _id;
        this.status = _status;
    }

    public async send() {
        let data = {
            objectid: this.id,
            status: this.status,
            objecttype: 1
        }
        try {
            await new Ajax('/article/articleCollect', data).post();
        } catch (e) {
            throw e;
        }
    }
}
/*ResearchDetailData*/
export interface ResearchDetailData {
    id: string;
    title: string;
    thumb: string;
    viewcount: string;
    collectcount: string;
    likecount: string;
    content: string;
    pdfurl: string;
    isfollow: number;
    islike: number;
}